package nancal.mp


import nancal.mp.db.mongo.entity.sys.AppMenu
import nancal.mp.db.mongo.mor
import nbcp.base.extend.ConvertJson
import nbcp.base.extend.FromListJson
import nbcp.base.extend.usingScope
import nbcp.myoql.db.db
import nbcp.myoql.db.mongo.*
import org.bson.Document
import org.junit.jupiter.api.Test

class SyncMongoTest :TestBase() {
    @Test
    fun syncMongoDevJenkinsData() {
        val targetDb = db.mongo.getMongoTemplateByUri("mongodb://dev:123@192.168.5.214:27017/cms")!!

        var list = listOf(mor.dev.gitServer, mor.dev.gitData, mor.dev.productLine)

        list.forEach { ent->
            usingScope(MongoTemplateScope(targetDb)){
                MongoDeleteClip(ent).exec()
            }

            MongoQueryClip(ent).toList().forEach {
                usingScope(MongoTemplateScope(targetDb)){
                    val insert = MongoBaseInsertClip(ent.userDefineTableName);
                    insert.addEntity(it);
                    insert.exec()
                }
            }
        }
    }
    @Test
    fun getMenu(){
        val jsonMenu="[{\"createAt\":\"2021-12-06 09:31:02\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61ad67d6f8587d4696ead1fd\",\"name\":\"成员与部门\",\"url\":\"/membership-division\",\"css\":\"icon-icon118\",\"code\":\"\",\"sort\":1.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2021-12-06 09:31:26\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61ad67eef8587d4696ead1fe\",\"name\":\"用户组\",\"url\":\"/user-group\",\"css\":\"icon-icon124\",\"code\":\"\",\"sort\":2.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2021-12-06 09:31:49\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61ad6805f8587d4696ead1ff\",\"name\":\"应用管理\",\"url\":\"/app-management\",\"css\":\"icon-icon04\",\"code\":\"\",\"sort\":3.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2021-12-06 09:32:21\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61ad6825f8587d4696ead200\",\"name\":\"资源管理\",\"url\":\"/resources-management\",\"css\":\"icon-modelku\",\"code\":\"\",\"sort\":4.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2021-12-06 09:32:55\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61ad6847f8587d4696ead201\",\"name\":\"角色管理\",\"url\":\"/role-management\",\"css\":\"icon-icon96\",\"code\":\"\",\"sort\":5.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2021-12-06 09:33:21\",\"updateAt\":\"2022-03-11 13:44:05\",\"id\":\"61ad6861f8587d4696ead202\",\"name\":\"授权管理\",\"url\":\"/author-management\",\"css\":\"icon-icon144\",\"code\":\"\",\"sort\":6.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2021-12-06 09:33:37\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61ad6871f8587d4696ead203\",\"name\":\"审计日志\",\"url\":\"/audit-log\",\"css\":\"icon-icon07\",\"code\":\"\",\"sort\":7.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2021-12-06 09:33:55\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61ad6883f8587d4696ead204\",\"name\":\"系统设置\",\"url\":\"/sys-setting\",\"css\":\"icon-set\",\"code\":\"\",\"sort\":8.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2022-01-03 19:33:55\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61c3e8abe5b1c57fd4ada807\",\"name\":\"管理员操作日志\",\"url\":\"/audit-log\",\"css\":\"\",\"code\":\"\",\"sort\":0.0,\"parent\":{\"id\":\"61ad6871f8587d4696ead203\",\"name\":\"审计日志\"}},{\"createAt\":\"2022-01-03 19:33:55\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61c3e8f3e5b1c57fd4ada80a\",\"name\":\"用户行为日志\",\"url\":\"/audit-log/userLog\",\"css\":\"\",\"code\":\"\",\"sort\":0.0,\"parent\":{\"id\":\"61ad6871f8587d4696ead203\",\"name\":\"审计日志\"}},{\"createAt\":\"2022-01-03 19:33:55\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61c96750f7199258e79adb63\",\"name\":\"基础设置\",\"url\":\"/sys-setting\",\"css\":\"\",\"code\":\"\",\"sort\":0.0,\"parent\":{\"id\":\"61ad6883f8587d4696ead204\",\"name\":\"系统设置\"}},{\"createAt\":\"2022-01-03 19:33:55\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"61c96793f7199258e79adb64\",\"name\":\"扩展字段\",\"url\":\"/sys-setting/extendedField\",\"css\":\"\",\"code\":\"\",\"sort\":0.0,\"parent\":{\"id\":\"61ad6883f8587d4696ead204\",\"name\":\"系统设置\"}},{\"createAt\":\"2022-02-08 17:23:28\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"62023690983988018a84c5cd\",\"name\":\"链接身份源\",\"url\":\"/identity-source\",\"css\":\"icon-icon07\",\"code\":\"\",\"sort\":5.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2022-02-08 17:58:00\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"62023ea8983988018a84c5d0\",\"name\":\"企业身份源\",\"url\":\"/identity-source\",\"css\":\"\",\"code\":\"\",\"sort\":0.0,\"parent\":{\"id\":\"62023690983988018a84c5cd\",\"name\":\"链接身份源\"}},{\"createAt\":\"2022-02-09 11:05:07\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"62032f63983988018a84c5e1\",\"name\":\"同步中心\",\"url\":\"/sync-center\",\"css\":\"icon-a-icon146\",\"code\":\"\",\"sort\":7.0,\"parent\":{\"id\":\"\",\"name\":\"\"}},{\"createAt\":\"2022-02-21 15:37:25\",\"updateAt\":\"2022-03-10 18:11:56\",\"id\":\"62134135dc68880d402e3c19\",\"name\":\"社会化身份源\",\"url\":\"/identity-source/socialIndex\",\"css\":\"\",\"code\":\"\",\"sort\":0.0,\"parent\":{\"id\":\"62023690983988018a84c5cd\",\"name\":\"链接身份源\"}}]\n"
        val menuList=jsonMenu.FromListJson(AppMenu::class.java)
        mor.sys.appMenu("mp-tenant-admin").delete().exec()
        menuList!!.forEach {
            val menu=it.ConvertJson(AppMenu::class.java).ConvertJson(Document::class.java)
            val emptyArray= arrayOf<String>()
            menu.set("menus",emptyArray )
            mor.sys.appMenu("mp-tenant-admin").doInsert(menu)
        }
    }
}